﻿/*
* 培训任务列表
* 
*/
var kdManagement = angular.module("trainingTask", ['tm.pagination', 'angularFileUpload', 'Common', 'knowledgebaseS', "loadModule", "trainingTaskAddEdit", "trainingTaskPreview", "trainingTaskComplete","btnconqitk"])
.controller("trainingTask", ["$scope", "$rootScope", "$state", "sysUserInfo", "RequestTrainService", "Comm", "Msg", "MsgCon", "FileUploader", function ($scope, $rootScope, $state, sysUserInfo, RTS, Comm, Msg, MsgCon, FileUploader) {
    $scope.btnlist = { savefun: false, addinfo: false, editinfo: false, delinfo: false };
    $rootScope.btnTab = "index.Train.task";
    //初始化
    $scope.init = function () {
        //培训任务列表集合
        $scope.trainingTaskList = [];
        // 显示隐藏 筛选进度 
        $scope.trainShow = false;
        // 选中个数
        $scope.checkAll = 0;
        //查询培训任务列表参数
        $scope.trainParams = {
            create_id: sysUserInfo.getuserinfo().user_ID,  //登录人id
            org_ID: sysUserInfo.getuserinfo().organization_ID, //登录人企业id
            powerLV: sysUserInfo.getuserinfo().powerLV, //权限id
            start_Date: "",  //开始时间
            end_Date: "",    //结束时间
            name: "",    //搜索内容、（知识结构名称或拼音）
            state: 0,    // 0 全部 1未开始，2进行中，3已完成
            searchUserId: "",    //搜索培训人员 （预留字段）
            pageIndex: 1,   //起始下标
            pageSize: 10 //页数
        }
        $scope.getTrainList();
    }
    //日期筛选
    $scope.GetDate = function () {
        $scope.trainParams.start_Date = document.getElementById("startDate").value;
        $scope.trainParams.end_Date = document.getElementById("endDate").value;
    }
    $scope.showUpdateTime=false;
    $scope.upCount=0;

    $scope.updateCount=function(){
        $scope.upCount++;
        if($scope.upCount>=5){
            $scope.showUpdateTime=true;
        }
    }


    $scope.taksComShow=false;
    $scope.openTaksComShow=function(item){
        if(item!=undefined){
            $scope.taskItem=item;
        }
       
        $scope.taksComShow=!$scope.taksComShow;
    }

    //全选
    $scope.selectAll = function () {
        $scope.selFlag = true;
        if ($scope.checkAll == $scope.trainingTaskList.length) { //已选
            $scope.selFlag = false;
            $scope.checkAll = 0;
        } else {
            $scope.selFlag = true;
            $scope.checkAll = $scope.trainingTaskList.length;
        }
        // 设置样式
        angular.forEach($scope.trainingTaskList, function (data, index, array) {
            data.isSel = $scope.selFlag;
        });
    }
    // 单选
    $scope.singleCheck = function (item) {
        if (item.isSel) {
            $scope.checkAll--;
            item.isSel = false;
        } else {
            $scope.checkAll++;
            item.isSel = true;
        }
    }
    /*
    *   遍历选中的对象
    *   list 集合
    *   serIds ref  id集合
    *   serItems ref obj集合不用传null
    */
    $scope.getParamsList = function (list, serIds, serItems) {
        angular.forEach(list, function (data, ind, arr) {//循环全部对象
            if (data.isSel) {// 找到选中的对象
                serIds.push(data.id); // 存id
                if (serItems != null)
                    serItems.push(data); // 存obj
            }
        });
    }
    $scope.selName = "全部";
    // 培训进度筛选
    $scope.trainSpeedSel = function (params) {
        //筛选情况
        $scope.trainParams.state = params;
        switch (params) {
            case 0: // 全部
                $scope.selName = "全部";
                break;
            case 1: //未开始
                $scope.selName = "未开始";
                break;
            case 2: //进行中
                $scope.selName = "进行中";
                break;
            case 3: //已完成
                $scope.selName = "已完成";
                break;

        }
        // 发送请求
        $scope.getTrainList();
    }
    //loading 加载
    $scope.trainingTaskLoading = false;
    //获取培训任务列表
    $scope.getTrainList = function () {
        //        console.log($scope.trainParams);
        $scope.trainingTaskLoading = true;
        RTS.findstage($scope.trainParams).then(function (response) {
            $scope.trainingTaskLoading = false;
            if (response.errorcode == "0") {
                $scope.trainingTaskList = response.datas;
                $scope.paginationConf.totalItems = response.numCount;
                $scope.paginationConf.currentPage = response.pageIndex;
            } else {
                Msg.error("获取列表失败了呦！");
            }
        }, function errorCallback() {
            console.log("连接服务器失败！");
        });
    }
    //回车事件
    $scope.findTrainListEnter = function (e) {
        var keycode = window.event ? e.keyCode : e.which;
        if (keycode == 13) {
            //            console.log('执行了回车');
            $scope.getTrainList();
        }
    }
    // 删除
    $scope.delinfo = function (item) {
        var ids = [];
        if (item == null) { // 判断是不是单个任务的删除
            $scope.getParamsList($scope.trainingTaskList, ids, null);
        } else {// 单独删除
            ids.push(item.id);
        }
        // 未选中
        if (Comm.isNull(ids) || ids.length <= 0) {
            Msg.info("请选择要删除的任务!");
            return;
        }
        //        console.log(ids);
        //提示框
        MsgCon.delnoicon().then(function (flag) {   // 删除弹框
            if (flag) {
                //                console.log(ids);
                // 发送请求
                RTS.deleteArrange({ arrangeIds: ids }).then(function (respose) {
                    if (respose.errorcode == "0") {
                        Msg.success("操作成功！");
                        $scope.checkAll = 0; // 复选框选中的数量            
                        $scope.getTrainList();  // 重新请求一下数据
                    } else if (respose.errorcode == "34") {
                        Msg.warning("此培训任务存在关联的课程信息");
                    } else {
                        Msg.error("操作失败！");
                        //                        console.log(respose.errorMsg); // 错误信息
                    }
                    //                    console.log(respose.numCount);  // 影响行数
                }, function errorCallback() {
                    console.log("连接服务器失败！");
                });
            }
        }, function (p) { console.log('error') });
    }
    //配置分页
    $scope.paginationConf = {
        currentPage: 1, //$location.search().currentPage ? $location.search().currentPage :  当前页码
        totalItems: 0,  // 总的记录数
        itemsPerPage: 10, // 每页显示多少条        
        perPageOptions: [10, 20],   // 每页显示记录数        
        onChange: function () {
            $scope.paginationConf.currentPage = $scope.paginationConf.currentPage == 0 ? 1 : $scope.paginationConf.currentPage;
            if ((parseInt($scope.trainParams.pageIndex) != parseInt($scope.paginationConf.currentPage)) || (parseInt($scope.trainParams.pageSize) != parseInt($scope.paginationConf.itemsPerPage))) {
                if ($scope.paginationConf.currentPage == 0) { $scope.paginationConf.currentPage = 1; }
                $scope.trainParams.pageIndex = $scope.paginationConf.currentPage;
                $scope.trainParams.pageSize = $scope.paginationConf.itemsPerPage;
                $scope.getTrainList();
            }
            $scope.checkAll = 0; // 复选框选中的数量     
        }
    };
    $scope.init();
    /*********************************************培训统计*******************************************/
    $scope.statisticOpen = function (item) {
        $rootScope.arrangeinfo = item;
        $state.go("index.Train.statistic");

    }
    /*********************************************新增编辑*******************************************/
    $scope.uploader = new FileUploader();
    // 新增编辑提示框
    $scope.taksAddEditShow = false;
    // 构造任务对象
    $scope.taskItem = {
        id: "",  // 任务id
        name: "",   // 任务名称
        org_ID: sysUserInfo.getuserinfo().organization_ID,  //所属组织机构
        arrage: "{}", // 人员对象
        org_Name: sysUserInfo.getuserinfo().organization_Name,
        create_id: sysUserInfo.getuserinfo().user_ID,   // 操作人
        is_public: false,    // 是否全可学
        start_Date: "",  // 开始日期
        end_Date: "",    // 结束日期
        userList: [],    // 用户
        userGroup: [],   // 用户组
        userOrganization: [], // 部门
        userRole: [],    // 角色
        arragetype: [], //培训任务json        
        qualified: false, // 是否通过学习后才能进入下一章节
        courser_count: 0, // 课程数
        date_formate: 0,     // 默认不限制  0 不限制 1固定周期  2固定日期  3 固定天数
        date_formate_time: "",   //   固定日期
        start_time: "00:00",
        end_time: "23:59",
        isReviewed: false, //是否报名参与
        fine_time: false,
        state: 0,   // （预留） 0 分配 1 自主报名
        integral: 0,
        qualified_condition: "", // 合格条件 1.学满学时，2.考核通过
        arrage_Description: "", //任务描述，简介
        qualified_pass: ""     //通过考核分数、时间（分钟）
    }
    // 添加编辑培训任务
    $scope.addinfo = function (item) {
        var ids = [];
        var items = [];
        if (item == null) { // 判断是不是单个任务的编辑
            $scope.getParamsList($scope.trainingTaskList, ids, items);
        } else {// 单独编辑
            items.push(item);
        }
        //        console.log(items);
        if (items != null && items.length == 1) { //编辑
            //            // 处理时间去掉前面两个
            //            if (items[0].hasOwnProperty("start_Date")) {
            //                // 时间 取得日期 去掉前两个 然后分组然后去第一个是日期  第二个是时间
            //                items[0].start_time = items[0].start_Date.split(' ')[1].split(':')[0] + ":" + items[0].start_Date.split(' ')[1].split(':')[1];
            //                items[0].start_Date = items[0].start_Date.toString().substring(2).split(' ')[0];
            //            }
            //            if (items[0].hasOwnProperty("end_Date")) {
            //                // 截取出来时间
            //                items[0].end_time = items[0].end_Date.split(' ')[1].split(':')[0] + ":" + items[0].end_Date.split(' ')[1].split(':')[1];
            //                items[0].end_Date = items[0].end_Date.toString().substring(2).split(' ')[0];
            //            }
            $scope.taskItem = angular.copy(items[0]);
        } else if (items != null && items.length > 1) { //  限制只能选择一个
            Msg.warning("只能编辑一条记录");
            return;
        } else { // 新增
            $scope.taskItem = {
                id: "",  // 任务id
                name: "",   // 任务名称
                arrage: "{}", // 人员对象
                org_ID: sysUserInfo.getuserinfo().organization_ID,  //所属组织机构
                org_Name: sysUserInfo.getuserinfo().organization_Name,
                create_id: sysUserInfo.getuserinfo().user_ID,   // 操作人
                is_public: false,    // 是否全可学
                start_Date: "",  // 开始日期
                end_Date: "",    // 结束日期
                userList: [],    // 用户
                userGroup: [],   // 用户组
                userOrganization: [], // 部门
                userRole: [],    // 角色
                arragetype: [], //培训任务json        
                qualified: false, // 是否通过学习后才能进入下一章节
                courser_count: 0, // 课程数
                date_formate: 0,     // 默认不限制  0 不限制 1固定周期  2固定日期  3 固定天数
                date_formate_time: "",   //   固定日期
                start_time: "00:00",
                end_time: "23:59",
                fine_time: false,
                state: 0,   // （预留） 0 分配 1 自主报名
                integral: 0,
                qualified_condition: '', // 合格条件 1.学满学时，2.考核通过
                qualified_pass: "",     //通过考核分数、时间（分钟）
                courseKnowIds: "", //勾选课程的知识架构id
                examKnowIds: "", //勾选课程的知识架构id
                arrage_Description: "", //任务描述，简介
                quesKnowsCount: 0, //勾选课程的知识架构id
                complete: { courseList: [], examList: [], queList: []}// 存储各种类型的知识分类
            }
        }
        $scope.taksAddEditShow = true;
    }
    // 关闭窗口
    $scope.onCloseTask = function () {
        $scope.taksAddEditShow = false;
        $scope.btnloading = false;
        //        console.log($scope.taskItem);
    }
    // 人员中的对象 flag 是否新建
    $scope.isUserNotNull = function (user, flag) {
        if (!user.hasOwnProperty('userList') || flag) // 知识结构
            user.userList = [];
        if (!user.hasOwnProperty('userOrganization') || flag) // 试卷
            user.userOrganization = [];
        if (!user.hasOwnProperty('userRole') || flag) // 文件 
            user.userRole = [];
        if (!user.hasOwnProperty('userGroup') || flag) //课程
            user.userGroup = [];
        return user;
    }
    //判断数组中四属性是否存在
    $scope.isTaskNotNull = function (list) {
        if (!list.hasOwnProperty('kssList')) // 知识结构
            list.kssList = [];
        if (!list.hasOwnProperty('kseList')) // 试卷
            list.kseList = [];
        if (!list.hasOwnProperty('ksfList')) // 文件 
            list.ksfList = [];
        if (!list.hasOwnProperty('kscList')) //课程
            list.kscList = [];
        if (!list.hasOwnProperty('value')) //课程
            list.value = "";
        return list;
    }
    // 保存计划
    $scope.onSaveTask = function () {
        //        console.log($scope.taskItem);
        //        if ($scope.taskItem.name == null || $scope.taskItem.name == "" || $scope.taskItem.name == undefined) {
        //            Msg.warning("请输入任务名称");
        //            return;
        //        

        var oldcourseList = [];
        var oldpaperList = [];
        var oldknowList = [];

        var newcourseList = [];
        var newpaperList = [];
        var newknowList = [];
        //删除 的课程  试卷 知识架构 集合
        if ($scope.taskItem.oldarragetype != null) {
            $scope.taskItem.oldarragetype.forEach(function (data, index) {
                oldcourseList = oldcourseList.concat(data.kscList);
                oldpaperList = oldpaperList.concat(data.kseList);
                oldknowList = oldknowList.concat(data.kssList);
            });
        }
        //编辑后 的课程 试卷 知识架构 集合
        if ($scope.taskItem.arragetype != null) {
            $scope.taskItem.arragetype.forEach(function (data, index) {
                newcourseList = newcourseList.concat(data.kscList);
                newpaperList = newpaperList.concat(data.kseList);
                newknowList = newknowList.concat(data.kssList);
            });
        }
        var delXid = {
            courseids: "",
            paperids: "",
            knowledgeids: ""
        };
        //获取已删除的课程id
        newcourseList.forEach(function (data, index) {
            oldcourseList.forEach(function (data1, index1) {
                if (data.course_Id == data1.course_Id) {
                    oldcourseList.splice(index1, 1);
                }
            });
        });
        oldcourseList.forEach(function (data1, index1) {
            delXid.courseids += (delXid.courseids.length > 0 ? ',' : '') + data1.course_Id;
        });
        //获取已删除的试卷id
        newpaperList.forEach(function (data, index) {
            oldpaperList.forEach(function (data1, index1) {
                if (data.paperId == data1.paperId) {
                    oldpaperList.splice(index1, 1);
                }
            });
        });
        oldpaperList.forEach(function (data1, index1) {
            delXid.paperids += (delXid.paperids.length > 0 ? ',' : '') + data1.paperId;
        });
        //获取已删除的知识架构id
        newknowList.forEach(function (data, index) {
            oldknowList.forEach(function (data1, index1) {
                if (data.knowledge_Id == data1.knowledge_Id) {
                    oldknowList.splice(index1, 1);
                }
            });
        });
        oldknowList.forEach(function (data1, index1) {
            delXid.knowledgeids += (delXid.knowledgeids.length > 0 ? ',' : '') + data1.knowledge_Id;
        });
        /**********************************************************************************************************************/
        //邮箱发送
        $scope.taskItem.send_flag = $scope.taskItem.arrage.send_flag;
        if ($scope.taskItem.send_flag == undefined || $scope.taskItem.send_flag == "" || $scope.taskItem.send_flag == null) {
            $scope.taskItem.send_flag = 1;
        }
        //编辑时初始
        if ($scope.taskItem.courseKnowIds == undefined) {
            $scope.taskItem.courseKnowIds = ""; //勾选课程的知识架构id
        }
        if ($scope.taskItem.examKnowIds == undefined) {
            $scope.taskItem.examKnowIds = ""; //勾选课程的知识架构id
        }
        if ($scope.taskItem.quesKnowsCount == undefined) {
            $scope.taskItem.quesKnowsCount = 0; //勾选课程的知识架构id
        }
        var course_count = 0;   // 记录总的课程数
        $scope.taskItem.complete = { courseList: [], examList: [], queList: [] };
        // 处理课程数，以及values
        angular.forEach($scope.taskItem.arragetype, function (data, index, array) { // 全部阶段信息
            data = $scope.isTaskNotNull(data);
            // 汇总当前阶段数量
            course_count += data.kscList.length + data.kseList.length + data.ksfList.length;
            //课程
            angular.forEach(data.kscList, function (cdata, index, array) {
                // 追加id
                data.value += cdata.course_Id + ',';
                if (cdata.course_Id.length <= 0) {
                    data.kscList.splice(index, 1);
                }
                if (cdata.hasOwnProperty('knowledgeJSON') && cdata.knowledgeJSON) {
                    var courseKnowObj = JSON.parse(cdata.knowledgeJSON);
                    // 课程中有可能存在多个分类
                    angular.forEach(courseKnowObj, function (ckdata, index) {
                        // 添加各种类型的知识分类供统计用knowledge_Id
                        $scope.taskItem.complete.courseList.push(ckdata.knowledge_Id);
                    });
                }
            });
            //试卷
            angular.forEach(data.kseList, function (edata, index, array) {
                // 追加id
                data.value += edata.paperId + ',';
                // 添加各种类型的知识分类供统计用
                $scope.taskItem.complete.examList.push(edata.knowledge_Id);
                //data.value.push(edata.paperId);
                if (edata.paperId.length <= 0) {
                    data.kseList.splice(index, 1);
                }
            });
            //知识结构
            angular.forEach(data.kssList, function (sdata, index, array) {
                // 追加id
                data.value += sdata.knowledge_Id + ',';
                if (sdata.knowledge_Id.length <= 0) {
                    data.kssList.splice(index, 1);
                }
                if (sdata.know_select_course) {
                    $scope.taskItem.courseKnowIds += sdata.knowledge_Id + ","; //勾选了课程
                    // 添加各种类型的知识分类供统计用
                    $scope.taskItem.complete.courseList.push(sdata.knowledge_Id);
                }
                if (sdata.know_select_exam) {
                    $scope.taskItem.examKnowIds += sdata.knowledge_Id + ","; //勾选了试卷
                    // 添加各种类型的知识分类供统计用
                    $scope.taskItem.complete.examList.push(sdata.knowledge_Id);
                }
                if (sdata.know_select_que) {
                    $scope.taskItem.quesKnowsCount = parseInt($scope.taskItem.quesKnowsCount) + 1;  //勾选了题库
                    // 添加各种类型的知识分类供统计用
                    $scope.taskItem.complete.queList.push(sdata.knowledge_Id);
                }

            });
            //文件            
            angular.forEach(data.ksfList, function (fdata, index, array) {
                // 追加id
                data.value += fdata.upId + ',';
                //data.value.push(fdata.upId);
            });
        });
        // 课程总数
        $scope.taskItem.course_count = course_count;
        //配置用户群信息
        $scope.taskItem = $scope.isUserNotNull($scope.taskItem, true);
        var userCount = $scope.taskItem.arrage;
        userCount = $scope.isUserNotNull(userCount, false);

        if ($scope.taskItem.name == null || $scope.taskItem.name == undefined || $scope.taskItem.name == "") {
            $scope.buildName = true;
        }
        var olduserlist = [];
        var oldgrouplist = [];
        var oldorganizaiotnlist = [];
        var oldrolelist = []
        //获取出已删除的人员
        if ($scope.taskItem.oldarrage != null) {
            olduserlist = $scope.taskItem.oldarrage.userList;
            oldgrouplist = $scope.taskItem.oldarrage.userGroup;
            oldorganizaiotnlist = $scope.taskItem.oldarrage.userOrganization;
            oldrolelist = $scope.taskItem.oldarrage.userRole;
        }
        //删除的id
        var delIds = {
            userids: "",
            orgids: "",
            roleids: "",
            groupids: ""
        };

        /*********************************************************************************************/
        //用户组
        angular.forEach(userCount.userGroup, function (gdata, index, array) {
            // 追加用户组id
            $scope.taskItem.userGroup.push(gdata.userGroup_ID);
            // if ($scope.buildName) {
            //     $scope.taskItem.name += gdata.userGroup_Name + ",";
            // }
            // //遍历老的，查询出已删除的id
            // angular.forEach(oldgrouplist, function (zdata, zindex, zarray) {
            //     if (gdata.userGroup_ID == zdata.userGroup_ID) {
            //         oldgrouplist.splice(zindex, 1);
            //     }
            // });
        });
        // oldgrouplist.forEach(function (data, index) {
        //     delIds.groupids += (delIds.groupids.length > 0 ? "," : "") + data.userGroup_ID;
        // });
        /*********************************************************************************************/
        //角色
        angular.forEach(userCount.userRole, function (rdata, index, array) {
            // 追加角色id
            $scope.taskItem.userRole.push(rdata.roles_ID);
            // if ($scope.buildName) {
            //     $scope.taskItem.name += rdata.roles_Name + ",";
            // }
            // //遍历老的，查询出已删除的id
            // angular.forEach(oldrolelist, function (zdata, zindex, zarray) {
            //     if (rdata.roles_ID == zdata.roles_ID) {
            //         oldrolelist.splice(zindex, 1);
            //     }
            // });
        });
        // oldrolelist.forEach(function (data, index) {
        //     delIds.roleids += (delIds.roleids.length > 0 ? "," : "") + data.roles_ID;
        // });
        /*********************************************************************************************/
        //部门
        angular.forEach(userCount.userOrganization, function (odata, index, array) {
            // 追加部门id
            $scope.taskItem.userOrganization.push(odata.organization_ID);
            // if ($scope.buildName) {
            //     $scope.taskItem.name += odata.organization_Name + ",";
            // }
            // //遍历老的，查询出已删除的id
            // angular.forEach(oldorganizaiotnlist, function (zdata, zindex, zarray) {
            //     if (odata.organization_ID == zdata.organization_ID) {
            //         oldorganizaiotnlist.splice(zindex, 1);
            //     }
            // });
        });
        // oldorganizaiotnlist.forEach(function (data, index) {
        //     delIds.orgids += (delIds.orgids.length > 0 ? "," : "") + data.organization_ID;
        // });
        /*********************************************************************************************/
        //人员            
        angular.forEach(userCount.userList, function (sdata, index, array) {
            // 追加人员id
            $scope.taskItem.userList.push(sdata.user_ID);
            // if ($scope.buildName) {
            //     $scope.taskItem.name += sdata.user_Name + ",";
            // }
            // //遍历老的，查询出已删除的id
            // angular.forEach(olduserlist, function (zdata, zindex, zarray) {
            //     if (sdata.user_ID == zdata.user_ID) {
            //         olduserlist.splice(zindex, 1);
            //     }
            // });
        });
        // olduserlist.forEach(function (data, index) {
        //     delIds.userids += (delIds.userids.length > 0 ? "," : "") + data.user_ID;
        // });
        /*********************************************************************************************/
        //        console.log($scope.taskItem);
        if ($scope.buildName) {
            if ($scope.taskItem.name.length > 20) {
                $scope.taskItem.name = "分给" + $scope.taskItem.name.substring(0, 15) + "...的任务";
            } else {
                $scope.taskItem.name = "分给" + $scope.taskItem.name + "...的任务";
            }
        }
        $scope.btnloading = true;

        $scope.taskItem.oldarrage = null;
        $scope.taskItem.oldarragetype = null;
        // $scope.taskItem.delIds = JSON.stringify(delIds);
        // $scope.taskItem.delXid = JSON.stringify(delXid);
        console.log($scope.taskItem);
        //零时初始化一下
        if ($scope.taskItem.integral == undefined || $scope.taskItem.integral == null) {
            $scope.taskItem.integral = 0;
        }

        

        var param=angular.copy($scope.taskItem)
        param.complete="";
		
        //param.arrage=JSON.stringify(param.arrage)
        //param.arragetype=JSON.stringify(param.arragetype)
		
        param.userList=$scope.taskItem.userList.join(",");
        param.userOrganization=$scope.taskItem.userOrganization.join(",");
        param.userRole=$scope.taskItem.userRole.join(",");
        param.userGroup=$scope.taskItem.userGroup.join(",");

        RTS.addUpdateArrange(param).then(function (response) {
            $scope.btnloading = false;
            if (response.errorcode = "0") {
                Msg.success("操作成功！");
                $scope.taksAddEditShow = false;
                $scope.buildName = false;
                $scope.init();
            } else {
                Msg.error("操作失败！");
            }
        }, function callback() {
            $scope.btnloading = false;
            console.log("请求数据有误");
        });
    }
    // 预览弹框
    $scope.previewShow = false;
    $scope.previewObj = {};
    $scope.openPreview = function (obj) {
        $scope.previewObj = obj;
        $scope.previewShow = true;
    }
    // 关闭弹框
    $scope.closePreview = function () {
        $scope.previewShow = false;
    }
    /*********************************************文件上传开始**********************************************/
    $scope.importExcel = function () {
        document.getElementById("excelFile").click();
    }
    var trainupfile = $scope.uploader;
    trainupfile.onWhenAddingFileFailed = function (item /*{File|FileLikeObject}*/, filter, options) {     // 选择文件后失败       0
        console.info('onWhenAddingFileFailed', item, filter, options);
    };
    trainupfile.onAfterAddingFile = function (fileItem) {  // 选择文件后 （成功）   0          
        console.info('onAfterAddingFile', fileItem);
        if (trainupfile.isUploading) {
            MsgCon.alert("有文件正在上传。。");
            return;
        } else {
            var upfileparam = "?userid=" + sysUserInfo.getuserinfo().user_ID + "&xtype=1&xid=" + $scope.trainImport.id;
            //上传文件路径
            fileItem.url = RTS.ExcelImport(upfileparam);
        }
    };
    trainupfile.onAfterAddingAll = function (addedFileItems) { // 选择文件后添加到队列   1 
        console.info('onAfterAddingAll', addedFileItems);
        if (trainupfile.isUploading) {
            Msg.info("有文件正在上传。。");
            return;
        } else {
            trainupfile.uploadAll();
        }
    };
    // 开始上传
    trainupfile.onBeforeUploadItem = function (item) {    // 2 上传之前一项
        console.info('onBeforeUploadItem', item);
        Msg.info("开始导入。。。");
    };
    trainupfile.onProgressItem = function (fileItem, progress) {   // 3 上传进度
        console.info('onProgressItem', fileItem, progress);
    };
    trainupfile.onProgressAll = function (progress) {      //4 队列进度
        console.info('onProgressAll', progress);
    };
    trainupfile.onSuccessItem = function (fileItem, response, status, headers) {   // 5上传成功
        console.info('onSuccessItem', fileItem, response, status, headers); //fileItem 请求信息 response: 返回值status: 返回状态  headers: 请求头 
        document.getElementById("excelFile").value = "";
        $scope.getLogList();
        if (response.data != undefined) {
            scope.exUserList.push(response.data);
        }
        if (response.errorcode == 0) {
            Msg.success("导入成功！");
        } else {
            Msg.error(response.errormsg);
        }
    };
    trainupfile.onErrorItem = function (fileItem, response, status, headers) {     // 5上传失败
        console.info('onErrorItem', fileItem, response, status, headers);
    };
    trainupfile.onCancelItem = function (fileItem, response, status, headers) {    //5取消上传
        console.info('onCancelItem', fileItem, response, status, headers);
    };
    trainupfile.onCompleteItem = function (fileItem, response, status, headers) {  //6     单文件上传完成
        console.info('onCompleteItem', fileItem, response, status, headers);

    };
    trainupfile.onCompleteAll = function () {  // 6 单文件上传完成或者队列上传完成的时候
        console.info('onCompleteAll');
    };
    /*********************************************文件上传结束**********************************************/
    $scope.showLog = false;
    $scope.trainImport = {}; //当前需要导入用户的的任务是
    $scope.openLog = function (obj) {
        if (!$scope.showLog) {
            $scope.trainImport = obj;
        }
        $scope.showLog = !$scope.showLog;
    }
    $scope.exUserList = [];
    //获取当前时间，格式YYYY-MM-DD
    $scope.getNowFormatDate = function () {
        var date = new Date();
        var seperator1 = "-";
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        var currentdate = year + seperator1 + month + seperator1 + strDate;
        return currentdate;
    }
    //计算日志的进度样式
    $scope.shownum = function (sta, num) {
        try {
            if (num.indexOf('/') > 0) {
                return sta + " (" + num + ")";
            } else {
                return sta;
            }
        } catch (e) { return sta; }
    }
    $scope.getclass = function (flag) {
        if (flag == "失败") {
            return "personneladdrysb";
        }
    }
    $scope.progressStryle = function (num) {
        try {
            if (num.indexOf('/') > 0) {
                num = (num.split('/')[0] / num.split('/')[1]) * 100;
            }
        } catch (e) { }
        if (num || num == 0) {//  有值的时候
            return { "width": num + "%" };
        } else {
            return { "width": "100%" };
        }
    }
    /****************************************************************************************************************************************/
} ]);
